import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.LoadDataParams;
import com.teamdev.jxbrowser.chromium.ba;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.net.URL;
import java.util.zip.CheckedOutputStream;

/**
 * Main
 *
 * @author <a href="morse.jiang@foxmail.com">JiangWen</a>
 * @version 1.0.0, 2019/6/11 0011 10:43
 */
public class MainRun {

  private String path = this.getClass().getResource("/").getPath();

  static {
    try {
      Field e = ba.class.getDeclaredField("e");
      e.setAccessible(true);
      Field f = ba.class.getDeclaredField("f");
      f.setAccessible(true);
      Field modifersField = Field.class.getDeclaredField("modifiers");
      modifersField.setAccessible(true);
      modifersField.setInt(e, e.getModifiers() & ~Modifier.FINAL);
      modifersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
      e.set(null, new BigInteger("1"));
      f.set(null, new BigInteger("1"));
      modifersField.setAccessible(false);
    } catch (Exception e1) {
      e1.printStackTrace();
    }
  }

  public static void main(String[] args) throws Exception {
    //    final String url = "https://www.baidu.com";
    String path = new Object() {
      public String getPath() {
        return this.getClass().getResource("/").getPath();
      }
    }.getPath().substring(1);
    path = path.replace("ile:/", "");
    path = path.substring(0, path.indexOf("target/") + "target/".length());
    File file = new File(path + "login");
    if (!file.exists()){
      FileUtil.loadRecourseFromJarByFolder("/login", path, FileUtil.class);
    }
    Browser browser = new Browser();
    BrowserView view = new BrowserView(browser);
    JFrame frame = new JFrame();
    frame.setTitle("百度VIP桌面端体验版");
    Image image = ImageIO.read(new URL(
      "https://ss3.bdstatic.com/-Po3dSag_xI4khGkpoWK1HF6hhy/wisegame/wh%3D68%2C68/sign=16e4d0659725bc312b08099e66f3bb89/adaf2edda3cc7cd9b60131723701213fb80e9168.jpg"));
    frame.setIconImage(image);
    frame.setSize(1280, 960);
    frame.add(view, BorderLayout.CENTER);
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
    frame.setResizable(true);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    String url = "file:///" + path + "login/index.html";
    browser.loadURL(url);

  }


}
